package com.sumainfor.wx.system.epc.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.system.epc.service.ReceiveService;
import com.sumainfor.wx.system.epc.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/6/12 18:56
 * @Description:
 */
@RestController
@RequestMapping("/receive")
public class ReceiveController {

    @Autowired
    ReceiveService ReceiveService;

    /**
     * 功能描述:
     * 获取当前用户的领用单列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 12:08
     */
    @GetMapping("/getReceiveList")
    public JsonResult getReceiveList(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout= ReceiveService.getReceiveListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getReceiveList=ReceiveService.getReceiveList(params);
        result=pageUtils.getJsonResult(getReceiveList, params, cout);
        return result;
    }

    /**
     * 功能描述: 
     * 根据领用单编号获取领用备件信息详情
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/12 20:08
     */
    @GetMapping("/getReceiveById")
    public JsonResult getReceiveById(@RequestParam Map<String,Object>params){
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"RecId"})){
            return  JsonResult.error("RecId不能为空！");
        }
        return JsonResult.success(ReceiveService.getReceiveById(params));
    }

    /**
     * 功能描述: 
     * 申请领用单主表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/13 10:36
     */
    @PostMapping("/AddReceive")
    public JsonResult AddReceive(@RequestBody Map<String,Object>params){
        if(ReceiveService.AddReceive(params)){
            return JsonResult.success("领用单生成成功！");
        }else{
            return JsonResult.error("服务器繁忙，请稍后重试！");
        }
    }

}
